﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Linq.Expressions;

using Mvc.XForms.Actions.Settings;
using Mvc.XForms.Actions;
using Mvc.XForms.Utilities;

namespace Mvc.XForms.Controls.Settings {
	public class TriggerSettings<TContext> {
		public ITrigger<TContext> Trigger { get; private set; }

		public TriggerSettings(ITrigger<TContext> trigger) {
			Trigger = trigger;
		}

		public override string ToString() {
			return Trigger.ValidateThenRender();
		}

		public TriggerSettings<TContext> Label(string label) {
			Trigger.Label = label;
			return this;
		}

		public TriggerSettings<TContext> Help(string help) {
			Trigger.Label = help;
			return this;
		}

		public TriggerSettings<TContext> Hint(string hint) {
			Trigger.Hint = hint;
			return this;
		}

		public TriggerSettings<TContext> Appearance(Appearance appearance) {
			Trigger.Appearance = appearance;
			return this;
		}

		public TriggerSettings<TContext> ID(string clientID) {
			Trigger.ClientID = clientID;
			return this;
		}

		public TriggerSettings<TContext> CssClass(string cssClass) {
			Trigger.CssClass.Add(cssClass);
			return this;
		}

		public TriggerSettings<TContext> Insert() {
			var act = new ActionInsert<TContext>();
			Trigger.Actions.Add(act);
			return this;
		}

		public TriggerSettings<TContext> Insert(Action<ActionInsertSettings<TContext>> actionInsert) {
			var act = new ActionInsert<TContext>();
			actionInsert(act.Settings);
			Trigger.Actions.Add(act);
			return this;
		}

		public TriggerSettings<TContext> Delete() {
			var act = new ActionDelete<TContext>();
			Trigger.Actions.Add(act);
			return this;
		}

		public TriggerSettings<TContext> Delete(Action<ActionDeleteSettings<TContext>> actionDelete) {
			var act = new ActionDelete<TContext>();
			actionDelete(act.Settings);
			Trigger.Actions.Add(act);
			return this;
		}

		public TriggerSettings<TContext> Send() {
			var act = new ActionSend();
			Trigger.Actions.Add(act);
			return this;
		}

		public TriggerSettings<TContext> Action(XFormEvent xformsEvent, string scriptFunction) {
			var action = new ActionAction() {
				Event = xformsEvent,
				JSFunction = scriptFunction
			};
			Trigger.Actions.Add(action);
			return this;
		}
	}
}
